<?php

$NRIC = $_REQUEST['barcode'];
$date = $_SESSION['selectedBackDate'];
$Username = $_SESSION['loginusername'];

include 'conn.php';




$result = mysql_query("Select * from attendancerecord where NRIC='$NRIC' AND DATE(SignInTimeStamp) like '$date%'");
if (mysql_num_rows($result) == 0) {
    $signInTimeStamp = $date . ' 00:00:00';
    $signOutTimeStamp = $date . ' 00:00:00';
    $sql = "INSERT INTO attendancerecord (NRIC, CentreId, SignInTimeStamp, SignOutTimeStamp, Status, AuditSignIn) 
              VALUES ( '$NRIC',
              (
              SELECT client.CentreId 
              FROM  client
              WHERE NRIC = '$NRIC'), '$signInTimeStamp','$signOutTimeStamp','BackDated', '$Username')";
    $result = @mysql_query($sql);

    if ($result) {
        echo "<font color='red'>Back Date Success!</font>";
    } else {
        echo "<font color='red'>Back Date NOT Successful!</font>";
    }
} else {
    echo "<font color='red'>Attendance for that elderly has been taken already!</font>";
}
?>	